{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: doctran in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (0.0.9)\n",
      "Requirement already satisfied: lxml<5.0.0,>=4.9.2 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from doctran) (4.9.2)\n",
      "Requirement already satisfied: openai<0.28.0,>=0.27.8 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from doctran) (0.27.8)\n",
      "Requirement already satisfied: presidio-analyzer<3.0.0,>=2.2.33 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from doctran) (2.2.33)\n",
      "Requirement already satisfied: presidio-anonymizer<3.0.0,>=2.2.33 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from doctran) (2.2.33)\n",
      "Requirement already satisfied: pydantic<2.0.0,>=1.10.9 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from doctran) (1.10.12)\n",
      "Requirement already satisfied: spacy<4.0.0,>=3.5.4 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from doctran) (3.6.0)\n",
      "Requirement already satisfied: tiktoken<0.4.0,>=0.3.3 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from doctran) (0.3.3)\n",
      "Requirement already satisfied: requests>=2.20 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from openai<0.28.0,>=0.27.8->doctran) (2.31.0)\n",
      "Requirement already satisfied: tqdm in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from openai<0.28.0,>=0.27.8->doctran) (4.65.0)\n",
      "Requirement already satisfied: aiohttp in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from openai<0.28.0,>=0.27.8->doctran) (3.8.4)\n",
      "Requirement already satisfied: regex in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from presidio-analyzer<3.0.0,>=2.2.33->doctran) (2023.5.5)\n",
      "Requirement already satisfied: tldextract in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from presidio-analyzer<3.0.0,>=2.2.33->doctran) (3.4.4)\n",
      "Requirement already satisfied: pyyaml in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from presidio-analyzer<3.0.0,>=2.2.33->doctran) (6.0)\n",
      "Requirement already satisfied: phonenumbers>=8.12 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from presidio-analyzer<3.0.0,>=2.2.33->doctran) (8.13.17)\n",
      "Requirement already satisfied: pycryptodome>=3.10.1 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from presidio-anonymizer<3.0.0,>=2.2.33->doctran) (3.18.0)\n",
      "Requirement already satisfied: typing-extensions>=4.2.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic<2.0.0,>=1.10.9->doctran) (4.5.0)\n",
      "Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.11 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (3.0.12)\n",
      "Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (1.0.4)\n",
      "Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (1.0.9)\n",
      "Requirement already satisfied: cymem<2.1.0,>=2.0.2 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (2.0.7)\n",
      "Requirement already satisfied: preshed<3.1.0,>=3.0.2 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (3.0.8)\n",
      "Requirement already satisfied: thinc<8.2.0,>=8.1.8 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (8.1.10)\n",
      "Requirement already satisfied: wasabi<1.2.0,>=0.9.1 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (1.1.2)\n",
      "Requirement already satisfied: srsly<3.0.0,>=2.4.3 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (2.4.7)\n",
      "Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (2.0.9)\n",
      "Requirement already satisfied: typer<0.10.0,>=0.3.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (0.7.0)\n",
      "Requirement already satisfied: pathy>=0.10.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (0.10.2)\n",
      "Requirement already satisfied: smart-open<7.0.0,>=5.2.1 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (6.3.0)\n",
      "Requirement already satisfied: numpy>=1.15.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (1.24.3)\n",
      "Requirement already satisfied: jinja2 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (3.1.2)\n",
      "Requirement already satisfied: setuptools in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (65.5.0)\n",
      "Requirement already satisfied: packaging>=20.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (21.3)\n",
      "Requirement already satisfied: langcodes<4.0.0,>=3.2.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from spacy<4.0.0,>=3.5.4->doctran) (3.3.0)\n",
      "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from packaging>=20.0->spacy<4.0.0,>=3.5.4->doctran) (3.1.0)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.20->openai<0.28.0,>=0.27.8->doctran) (3.1.0)\n",
      "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.20->openai<0.28.0,>=0.27.8->doctran) (2.10)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.20->openai<0.28.0,>=0.27.8->doctran) (2.0.4)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.20->openai<0.28.0,>=0.27.8->doctran) (2022.12.7)\n",
      "Requirement already satisfied: blis<0.8.0,>=0.7.8 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.2.0,>=8.1.8->spacy<4.0.0,>=3.5.4->doctran) (0.7.10)\n",
      "Requirement already satisfied: confection<1.0.0,>=0.0.1 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from thinc<8.2.0,>=8.1.8->spacy<4.0.0,>=3.5.4->doctran) (0.1.0)\n",
      "Requirement already satisfied: colorama in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from tqdm->openai<0.28.0,>=0.27.8->doctran) (0.4.6)\n",
      "Requirement already satisfied: click<9.0.0,>=7.1.1 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from typer<0.10.0,>=0.3.0->spacy<4.0.0,>=3.5.4->doctran) (8.1.3)\n",
      "Requirement already satisfied: attrs>=17.3.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from aiohttp->openai<0.28.0,>=0.27.8->doctran) (23.1.0)\n",
      "Requirement already satisfied: multidict<7.0,>=4.5 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from aiohttp->openai<0.28.0,>=0.27.8->doctran) (6.0.4)\n",
      "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from aiohttp->openai<0.28.0,>=0.27.8->doctran) (4.0.2)\n",
      "Requirement already satisfied: yarl<2.0,>=1.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from aiohttp->openai<0.28.0,>=0.27.8->doctran) (1.9.1)\n",
      "Requirement already satisfied: frozenlist>=1.1.1 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from aiohttp->openai<0.28.0,>=0.27.8->doctran) (1.3.3)\n",
      "Requirement already satisfied: aiosignal>=1.1.2 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from aiohttp->openai<0.28.0,>=0.27.8->doctran) (1.3.1)\n",
      "Requirement already satisfied: MarkupSafe>=2.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from jinja2->spacy<4.0.0,>=3.5.4->doctran) (2.1.2)\n",
      "Requirement already satisfied: requests-file>=1.4 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from tldextract->presidio-analyzer<3.0.0,>=2.2.33->doctran) (1.5.1)\n",
      "Requirement already satisfied: filelock>=3.0.8 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from tldextract->presidio-analyzer<3.0.0,>=2.2.33->doctran) (3.12.2)\n",
      "Requirement already satisfied: six in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests-file>=1.4->tldextract->presidio-analyzer<3.0.0,>=2.2.33->doctran) (1.16.0)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "[notice] A new release of pip is available: 23.1.2 -> 23.2.1\n",
      "[notice] To update, run: python.exe -m pip install --upgrade pip\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: langchain in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (0.0.247)\n",
      "Requirement already satisfied: PyYAML>=5.4.1 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from langchain) (6.0)\n",
      "Requirement already satisfied: SQLAlchemy<3,>=1.4 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from langchain) (1.4.48)\n",
      "Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from langchain) (3.8.4)\n",
      "Requirement already satisfied: dataclasses-json<0.6.0,>=0.5.7 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from langchain) (0.5.7)\n",
      "Requirement already satisfied: langsmith<0.1.0,>=0.0.11 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from langchain) (0.0.14)\n",
      "Requirement already satisfied: numexpr<3.0.0,>=2.8.4 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from langchain) (2.8.4)\n",
      "Requirement already satisfied: numpy<2,>=1 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from langchain) (1.24.3)\n",
      "Requirement already satisfied: openapi-schema-pydantic<2.0,>=1.2 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from langchain) (1.2.4)\n",
      "Requirement already satisfied: pydantic<2,>=1 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from langchain) (1.10.12)\n",
      "Requirement already satisfied: requests<3,>=2 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from langchain) (2.31.0)\n",
      "Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from langchain) (8.2.2)\n",
      "Requirement already satisfied: attrs>=17.3.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (23.1.0)\n",
      "Requirement already satisfied: charset-normalizer<4.0,>=2.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (3.1.0)\n",
      "Requirement already satisfied: multidict<7.0,>=4.5 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (6.0.4)\n",
      "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (4.0.2)\n",
      "Requirement already satisfied: yarl<2.0,>=1.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.9.1)\n",
      "Requirement already satisfied: frozenlist>=1.1.1 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.3.3)\n",
      "Requirement already satisfied: aiosignal>=1.1.2 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.3.1)\n",
      "Requirement already satisfied: marshmallow<4.0.0,>=3.3.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from dataclasses-json<0.6.0,>=0.5.7->langchain) (3.19.0)\n",
      "Requirement already satisfied: marshmallow-enum<2.0.0,>=1.5.1 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from dataclasses-json<0.6.0,>=0.5.7->langchain) (1.5.1)\n",
      "Requirement already satisfied: typing-inspect>=0.4.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from dataclasses-json<0.6.0,>=0.5.7->langchain) (0.8.0)\n",
      "Requirement already satisfied: typing-extensions>=4.2.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pydantic<2,>=1->langchain) (4.5.0)\n",
      "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests<3,>=2->langchain) (2.10)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests<3,>=2->langchain) (2.0.4)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests<3,>=2->langchain) (2022.12.7)\n",
      "Requirement already satisfied: greenlet!=0.4.17 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from SQLAlchemy<3,>=1.4->langchain) (2.0.2)\n",
      "Requirement already satisfied: packaging>=17.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from marshmallow<4.0.0,>=3.3.0->dataclasses-json<0.6.0,>=0.5.7->langchain) (21.3)\n",
      "Requirement already satisfied: mypy-extensions>=0.3.0 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from typing-inspect>=0.4.0->dataclasses-json<0.6.0,>=0.5.7->langchain) (1.0.0)\n",
      "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\\users\\user\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from packaging>=17.0->marshmallow<4.0.0,>=3.3.0->dataclasses-json<0.6.0,>=0.5.7->langchain) (3.1.0)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n",
      "[notice] A new release of pip is available: 23.1.2 -> 23.2.1\n",
      "[notice] To update, run: python.exe -m pip install --upgrade pip\n"
     ]
    }
   ],
   "source": [
    "!pip install doctran\n",
    "!pip install langchain"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from dotenv import load_dotenv\n",
    "load_dotenv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.schema import Document\n",
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "complaint_email_content = \"\"\"\n",
    "Dear Mustang Motors Team,\n",
    "\n",
    "I'm writing to express my dissatisfaction with a recent car purchase (Mustang GT). Regrettably, the car hasn't lived up to my expectations, and I would like to request a refund.\n",
    "\n",
    "The car's functionality and performance have not matched the quality advertised through your marketing initiatives and previous customer testimonials. The innovative design and features, as touted by your R&D department, seem inconsistent with the actual vehicle.\n",
    "\n",
    "Could you please guide me through the refund process? I trust in your ability to resolve this issue promptly and satisfactorily.\n",
    "\n",
    "Thank you for your attention to this matter.\n",
    "\n",
    "Best regards,\n",
    "\n",
    "Max Müller\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.document_transformers import DoctranPropertyExtractor\n",
    "\n",
    "documents = [Document(page_content=complaint_email_content)]\n",
    "properties = [\n",
    "    {\n",
    "        \"name\": \"category\",\n",
    "        \"description\": \"The type of email this is.\",\n",
    "        \"type\": \"string\",\n",
    "        \"enum\": [\"complaint\", \"refund_request\", \"product_feedback\", \"customer_service\", \"other\"],\n",
    "        \"required\": True,\n",
    "    },\n",
    "    {\n",
    "        \"name\": \"mentioned_product\",\n",
    "        \"description\": \"The product mentioned in this email.\",\n",
    "        \"type\": \"string\",\n",
    "        \"required\": True,\n",
    "    },\n",
    "    {\n",
    "        \"name\": \"issue_description\",\n",
    "        \"description\": \"A brief explanation of the problem encountered with the product.\",\n",
    "        \"type\": \"string\",\n",
    "        \"required\": True,\n",
    "    }\n",
    "]\n",
    "property_extractor = DoctranPropertyExtractor(properties=properties, openai_api_model=\"gpt-3.5-turbo\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"extracted_properties\": {\n",
      "    \"category\": \"refund_request\",\n",
      "    \"mentioned_product\": \"Mustang GT\",\n",
      "    \"issue_description\": \"Car functionality and performance not as advertised\"\n",
      "  }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "extracted_document = await property_extractor.atransform_documents(\n",
    "    documents, properties=properties\n",
    ")\n",
    "print(json.dumps(extracted_document[0].metadata, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.schema import Document\n",
    "from langchain.document_transformers import DoctranQATransformer\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "documents = [Document(page_content=complaint_email_content)]\n",
    "qa_transformer = DoctranQATransformer(openai_api_model=\"gpt-3.5-turbo\")\n",
    "transformed_document = await qa_transformer.atransform_documents(documents)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"questions_and_answers\": [\n",
      "    {\n",
      "      \"question\": \"What is the reason for your dissatisfaction with the car?\",\n",
      "      \"answer\": \"The car's functionality and performance have not matched the quality advertised through your marketing initiatives and previous customer testimonials. The innovative design and features, as touted by your R&D department, seem inconsistent with the actual vehicle.\"\n",
      "    },\n",
      "    {\n",
      "      \"question\": \"What specific issues have you encountered with the car?\",\n",
      "      \"answer\": \"The car's functionality and performance have not lived up to my expectations. It lacks the power and acceleration that were promised, and there have been several mechanical issues since I purchased it.\"\n",
      "    },\n",
      "    {\n",
      "      \"question\": \"Have you contacted our customer service regarding this issue?\",\n",
      "      \"answer\": \"No, I haven't contacted customer service yet.\"\n",
      "    },\n",
      "    {\n",
      "      \"question\": \"Would you like us to arrange a meeting with our customer service team to discuss your concerns?\",\n",
      "      \"answer\": \"Yes, I would appreciate a meeting with your customer service team to discuss my concerns and explore the possibility of a refund.\"\n",
      "    }\n",
      "  ]\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "print(json.dumps(transformed_document[0].metadata, indent=2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.document_transformers import DoctranTextTranslator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "documents = [Document(page_content=complaint_email_content)]\n",
    "qa_translator = DoctranTextTranslator(language=\"german\", openai_api_model=\"gpt-3.5-turbo\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Sehr geehrtes Mustang Motors Team,\\n\\nich schreibe Ihnen, um meine Unzufriedenheit mit einem kürzlichen Autokauf (Mustang GT) zum Ausdruck zu bringen. Bedauerlicherweise hat das Auto nicht meinen Erwartungen entsprochen, und ich möchte eine Rückerstattung beantragen.\\n\\nDie Funktionalität und Leistung des Autos haben nicht der Qualität entsprochen, die durch Ihre Marketinginitiativen und frühere Kundenbewertungen beworben wurde. Das innovative Design und die Funktionen, wie sie von Ihrer Forschungs- und Entwicklungsabteilung angepriesen wurden, scheinen nicht mit dem tatsächlichen Fahrzeug übereinzustimmen.\\n\\nKönnten Sie mich bitte durch den Rückerstattungsprozess führen? Ich vertraue darauf, dass Sie dieses Problem schnell und zufriedenstellend lösen können.\\n\\nVielen Dank für Ihre Aufmerksamkeit in dieser Angelegenheit.\\n\\nMit freundlichen Grüßen,\\n\\nMax Müller'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "translated_document = await qa_translator.atransform_documents(documents)\n",
    "translated_document[0].page_content"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
